package com.lpf.arg;

import com.lpf.UserParam;
import org.springframework.core.MethodParameter;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.support.WebDataBinderFactory;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.ModelAndViewContainer;

@Component
public class ArgumentResolve implements HandlerMethodArgumentResolver {

    // 判断你的参数是否由当前适配器来处理
    @Override
    public boolean supportsParameter(MethodParameter methodParameter) {
        // 如果是 spring mvc 的话，可能就是：当前参数如果是String
        return methodParameter.hasParameterAnnotation(UserParam.class);
    }

    // 给支参数赋的值
    @Override
    public Object resolveArgument(MethodParameter methodParameter, ModelAndViewContainer modelAndViewContainer, NativeWebRequest nativeWebRequest, WebDataBinderFactory webDataBinderFactory) throws Exception {
        // 如果是 spring mvc 的话，可能就是：通过 httpServletRequest.getParameter() 获取值
        return "loginUser";
    }
}
